package com.vast.ui.component.models;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.ListenerList;

import com.vast.ui.component.socketinterface.listner.IReceiveListener;

public class ItemPanel implements IReceiveListener {
	private final  List<ItemArray> itemArrayList;
	private final  ListenerList listenerList;

	public ItemPanel() {
		this.itemArrayList = new ArrayList<ItemArray>();
		this.listenerList  = new ListenerList();
	}
	
	public List<ItemArray> getList(){
		return itemArrayList;
	}
	
	public void add(ItemArray itemArray){
		itemArrayList.add(itemArray);
		Object[] listeners = listenerList.getListeners();
		for (Object listener : listeners) {
			((ItemArrayListener) listener).add(itemArray);
		}
	}
	
	public void remove(ItemArray itemArray){
		itemArrayList.remove(itemArray);
		Object[] listeners = listenerList.getListeners();
		for (Object listener : listeners) {
			((ItemArrayListener) listener).remove(itemArray);
		}
	}
	
	public void addListener(ItemArrayListener listener){
		listenerList.add(listener);
	}
	
	public void removeListener(ItemArrayListener listener){
		listenerList.remove(listener);
	}
	
	public void changeTarget(int index, ItemArray itemArray) {
		itemArrayList.set(index,itemArray);
	}
	
	public void clear() {
		itemArrayList.clear();
		listenerList.clear();
	}
	
	public int getNumberOfColumn(){
		if(itemArrayList.size() > 0) {
			ItemArray itemArray = itemArrayList.get(0);
			return itemArray.size();
		} else {
			return 0;
		}
	}

	public void received(byte[] data) {
		// TODO Auto-generated method stub
		Short CommandType = (short) ((data[2] << 8) + (data[3] << 0));
		
		
	}
}
